package com.sunyifeng.ch03;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

/**
 * 3.4.3 java.util.function.Function<T, R>定义了apply(T t)的方法，无返回值
 */
public class FunctionApply {

    public static <T, R> List<R> map(List<T> list, Function<T, R> f) {
        List<R> result = new ArrayList<>();
        for(T s: list) {
            result.add(f.apply(s));
        }
        return result;
    }

    public static void main(String[] args) {
        List<Integer> list = map(Arrays.asList("lambdas", "in", "action"),
                (String s) -> s.length());
        System.out.println(list);
    }

}
